﻿using System.Windows;
using DSPL.Services;
using DSPL.Contracts;
using DSPL.Common;
using System.Data;
using DSPL.Services.Services;
using DSPL.Contracts.Common;
using DSPL.Contracts.ViewModel;
using DSPL.Contracts.Command;
using DSPL.Finac.Common;

namespace DSPL.Finac.ViewModel
{
    public class ProductGroupViewModel : BaseViewModel
    {
        private bool isGroupCodeFocused;
        private bool isGroupNameFocused;

        #region Define properties
        public bool IsGroupCodeFocused
        {
            get { return isGroupCodeFocused; }
            set
            {
                isGroupCodeFocused = value;
                this.OnPropertyChanged("IsGroupCodeFocused");
            }
        }

        public bool IsGroupNameFocused
        {
            get { return isGroupNameFocused; }
            set
            {
                isGroupNameFocused = value;
                this.OnPropertyChanged("IsGroupNameFocused");

            }
        } 
        #endregion

        
        #region Constructor

        public ProductGroupViewModel()
            : base()
        {
            MessageTitle =  "Product Group Master";
        }

        #endregion
        /// <summary>
        /// Validate mandatory data before save
        /// </summary>
        /// <param name="obj"></param>
        protected override void PreDataValidateExecuted(object obj)
        {
            IsGroupCodeFocused = false;
            IsGroupNameFocused = false;

            var messageService = new MessageService();
            if (CurrentRow["GroupCode"].ToString().Trim() == string.Empty)
            {
                messageService.ShowMessage(MessageText.ProductGroupCodeNotEmpty, MessageTitle,  MessageType.InfoOK);
                IsGroupCodeFocused = true;
                this.IsValid = false;
                return;
            }

            if (CurrentRow["GroupName"].ToString().Trim() == string.Empty)
            {
                messageService.ShowMessage(MessageText.ProductGroupNameNotEmpty,MessageTitle, MessageType.InfoOK);
                IsGroupNameFocused = true;
                this.IsValid = false;
                return;
            }
            this.IsValid = true;
        }
    }
}